package start.demo01.erupt;

import org.junit.Test;

public class Main {

    private boolean flag = false;

    @Test
    public void t3() {
        new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            flag = true;
            System.out.println("flag = " + flag);
        }).start();
        while (true) {
            if (flag) {
                System.out.println("主线程访问到 flag 变量");
            }
            else
                System.out.println("flag");
        }
    }

    @Test
    public void t2() throws InterruptedException {
        new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("enter 2 线程");
            flag = false;
        }).start();
        System.out.println("进入线程循环");
        while (true) {
            Thread.sleep(500);
            if (flag) {
                System.out.println("11" + flag);
            } else
                System.out.println("11");
        }
    }

    public void t1() throws InterruptedException {
        Thread t = new Thread();
        t.start();
        t.wait();
    }

    @Test
    public void t0() throws InterruptedException {
        Object o;
        Thread a = new Thread();
        a.join();
        a.wait();
    }
}
